import 'package:app/common/tool.dart';
import 'package:app/components/base_scaffold_appbar.dart';
import 'package:app/components/nodata_page.dart';
import 'package:app/pages/reward_modules/reward_controller.dart';
import 'package:app/pages/reward_modules/reward_detail_module/reward_detail_view.dart';
import 'package:bruno/bruno.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:get/get.dart';

import '../../common/app_theme.dart';
import '../../common/colors.dart';
import '../../components/custom_footer.dart';
import '../../services/address.dart';
import 'RewardModel.dart';

class RewardView extends GetView{

  RewardController controller  = Get.put(RewardController());


  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: BaseAppBar(
        preferredSize: Size(Get.width, AppTool.appBarHEIGHT),
        child: Text('奖惩'),
      ),
      body: GetBuilder<RewardController>(builder: (_){
        return Column(
          children: [
            Container(
              color: Colors.white,
              height: 50,
              child: Row(
                children: [
                  Container(
                    color: Colors.white,
                    margin: EdgeInsets.only(left: 25),
                    child: Row(
                      children: [
                        GestureDetector(
                          child: Text(
                            controller.replyType,
                            style: appThemeData.textTheme.bodyText1!
                                .copyWith(fontSize: 15),
                          ),
                          onTap: () => controller.topClick(),
                        ),
                        SizedBox(width: 5,),
                        controller.isTopShow == false
                            ? Image.asset(
                          'images/arrow-down.png',
                          width: 12,
                          height: 12,
                        )
                            : Image.asset(
                          'images/arrow-up.png',
                          width: 12,
                          height: 12,
                          color: AppColor.themeColor,
                        )
                      ],
                    ),
                  ),
                  Container(
                      decoration: BoxDecoration(
                          color: AppColor.bgColor,
                          borderRadius:
                          BorderRadius.all(Radius.circular(13))),
                      width: Get.width - 150,
                      alignment: Alignment.centerLeft,
                      margin: EdgeInsets.only(top: 0, left: 10, right: 10),
                      padding: EdgeInsets.only(left: 15),
                      height: 30,
                      child: Row(
                        children: [
                          Image.asset('images/top_search.png',width: 15,height: 15,),
                          Container(
                            padding: EdgeInsets.only(left: 5),
                            alignment: Alignment.center,
                            color: Colors.transparent,
                            width: Get.width - 200,
                            height: 30,
                            child: TextField(
                              controller: controller.searchTextEditingController,
                              onChanged: (values) {
                                // requestData(search: values);
                                controller.requestData(search: values);
                              },
                              decoration: InputDecoration(
                                  isCollapsed: true,
                                  border: InputBorder.none,
                                  hintText: '请输入关键词',
                                  hintStyle: TextStyle(
                                      color: AppColor.hintColor,
                                      fontSize: 13)),
                              style: TextStyle(
                                  color: AppColor.smallTextColor,
                                  fontSize: 14),
                            ),
                          )
                        ],
                      )),
                ],
              ),
            ),
            Expanded(child: EasyRefresh.custom(
              controller: controller.easyRefreshController,
              onRefresh: ()=>controller.onRefresh(),
              onLoad: ()=>controller.onLoad(),
              footer: MaterialFooter1(),
              emptyWidget: controller.dataArr.isEmpty?NoDataPage():null,
              slivers: [
                SliverList(
                  delegate: _mySliverChildBuilderDelegate(),
                ),
              ],
            )),
          ],
        );
      }),
    );
  }
  _mySliverChildBuilderDelegate() {
    return SliverChildBuilderDelegate(
          (BuildContext context, int index) {
            RewardItemModel model = controller.dataArr[index];
        return GestureDetector(
          onTap: ()async{
            Get.to(RewardDetailPage(model.id));
          },
          child: Container(
            height: 120,
            padding: EdgeInsets.only(top: 10),
            child:  Row(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Container(
                  width: 65,
                  color: Colors.white,
                  padding: EdgeInsets.only(top: 15,left: 20),
                  alignment: Alignment.topLeft,
                  child: Image.asset('images/award_icon.png',width: 40,height: 40,),
                ),
                Expanded(child: Container(
                  width: Get.width-10,
                  color: Colors.white,
                  padding: EdgeInsets.all(10),
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.start,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Container(
                        color: Colors.white,
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Container(
                              width: 200,
                              padding: EdgeInsets.only(left: 0,right: 0),
                              child: Text('${model.typeName}',
                                style: appThemeData.textTheme.bodyText1!.
                                copyWith(fontWeight: FontWeight.w500,fontSize: 16),maxLines: 1,),
                            ),
                            model.status ==''?SizedBox():Container(
                              decoration: BoxDecoration(
                                  color: Colors.red.withAlpha(50),
                                  borderRadius: BorderRadius.all(Radius.circular(15))
                              ),
                              padding: EdgeInsets.only(left: 5,right: 5,top: 1,bottom: 2),
                              child: Row(
                                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                children: [
                                  Text('${model.status}'
                                    ,style: appThemeData.textTheme.subtitle1?.copyWith(
                                        color: Colors.red ,fontSize: 11
                                    ),),
                                ],
                              ),
                            ),
                          ],
                        ),
                      ),
                      SizedBox(height: 5,),

                      Container(
                        padding: EdgeInsets.only(left: 0,right: 5),
                        child: Text('项目:${model.cases}',
                          style: appThemeData.textTheme.subtitle1!,),
                      ),
                      SizedBox(height: 5,),

                      Container(
                        padding: EdgeInsets.only(left: 0,right: 5),
                        child: Text('奖金:${model.money}元',
                          style: appThemeData.textTheme.subtitle1!,),
                      ),
                      SizedBox(height: 5,),

                      Container(
                        padding: EdgeInsets.only(left: 0,right: 5),
                        child: Text('日期:${model.date}',
                          style: appThemeData.textTheme.subtitle1!,),
                      ),


                      // Text('请假类型：${model.typeName!}'),
                      // Text('开始时间：${model.dateStart!}'),
                      // Text('结束时间：${model.dateEnd!}'),
                      // Text('持续时间：${model.duration!}'),
                      // SizedBox(height: 15,),

                    ],
                  ),
                ),),
              ],
            ),
          ),
        );
      },
      childCount: controller.dataArr.length,
    );
  }

}